package com.hzhq.contract.convert;

import com.hzhq.contract.bean.dto.ContractDTO;
import com.hzhq.contract.bean.entity.Contract;
import com.hzhq.contract.bean.vo.ContractVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

/**
 * @author: hzhq1255
 * @mail: hzhq1255@163.com
 * @date: 2021/4/14 23:39
 * @desc:
 */
@Mapper
public interface ContractConvertBasic {

    ContractConvertBasic INSTANCE = Mappers.getMapper(ContractConvertBasic.class);


    @Mappings({
            @Mapping(target = "companiesA", expression = "java(com.hzhq.contract.convert.method.ContractConvertMethod.companiesToCompaniesDto(source.getCompaniesA()))"),
            @Mapping(target = "companiesB", expression = "java(com.hzhq.contract.convert.method.ContractConvertMethod.companiesToCompaniesDto(source.getCompaniesB()))"),
//            @Mapping(target = "attachmentList", expression = "java(com.hzhq.contract.convert.method.ContractConvertMethod.attachmentsToAttachmentsDto(source.getAttachmentList()))"),
//            @Mapping(target = "statusList", expression = "java(com.hzhq.contract.convert.method.ContractConvertMethod.statusesToStatusesDto(source.getStatusList()))"),
//            @Mapping(target = "currentAmount",expression = "java(com.hzhq.contract.convert.method.ContractConvertMethod.getCurrentAmount(source.getStatusList()))")
    })
    ContractDTO poToDto(Contract source);

    @Mappings({
            @Mapping(target = "companiesA", expression = "java(com.hzhq.contract.convert.method.ContractConvertMethod.companiesDtoToCompanies(source.getCompaniesA()))"),
            @Mapping(target = "companiesB", expression = "java(com.hzhq.contract.convert.method.ContractConvertMethod.companiesDtoToCompanies(source.getCompaniesB()))"),
//            @Mapping(target = "attachmentList", expression = "java(com.hzhq.contract.convert.method.ContractConvertMethod.attachmentsDtoToAttachments(source.getAttachmentList()))"),
//            @Mapping(target = "statusList", expression = "java(com.hzhq.contract.convert.method.ContractConvertMethod.statusesDtoToStatuses(source.getStatusList()))")
    })
    Contract dtoToPo(ContractDTO source);

    @Mappings({
            @Mapping(target = "companiesA", expression = "java(com.hzhq.contract.convert.method.ContractConvertMethod.companiesDtoToString(source.getCompaniesA()))"),
            @Mapping(target = "companiesB", expression = "java(com.hzhq.contract.convert.method.ContractConvertMethod.companiesDtoToString(source.getCompaniesB()))"),
//            @Mapping(target = "attachmentList", expression = "java(com.hzhq.contract.convert.method.ContractConvertMethod.attachmentsDtoToAttachmentsVo(source.getAttachmentList()))"),
//            @Mapping(target = "statusList", expression = "java(com.hzhq.contract.convert.method.ContractConvertMethod.statusesDtoToStatusesVo(source.getStatusList()))"),
            @Mapping(target = "contractId", expression = "java(com.hzhq.contract.util.ConvertUtil.objectIdToString(source.getContractId()))"),
            @Mapping(target = "templateId", expression = "java(com.hzhq.contract.util.ConvertUtil.objectIdToString(source.getTemplateId()))"),
            @Mapping(target = "contractType", expression = "java(source.getContractType() == null ? null: source.getContractType().getTypeName())"),
            @Mapping(target = "depart", expression = "java(source.getDepart() == null ? null : source.getDepart().getDepartName())"),
            @Mapping(target = "createUser", expression = "java(source.getCreateUser() == null ? null: source.getCreateUser().getUsername())"),
//            @Mapping(target = "lastEditedUser", expression = "java(source.getLastEditedUser() == null ? null : source.getLastEditedUser().getUsername())"),
//            @Mapping(target = "approvalPerson", expression = "java(source.getApprovalPerson() == null ? null : source.getApprovalPerson().getUsername())"),
            @Mapping(target = "contactInfo", expression = "java(com.hzhq.contract.convert.method.ContractConvertMethod.getContactInfo(source.getContactPerson(),source.getContactPhone()))")
    })
    ContractVO dtoToVo(ContractDTO source);


//    @Mappings({
//            @Mapping(target = "contractId",expression = "java(source.getContractId() == null || !org.bson.types.ObjectId.isValid(source.getContractId()) ? new org.bson.types.ObjectId() : new org.bson.types.ObjectId(source.getContractId()))"),
//            @Mapping(target = "templateId",expression = "java(source.getContractId() == null || !org.bson.types.ObjectId.isValid(source.getContractId()) ? new org.bson.types.ObjectId() : new org.bson.types.ObjectId(source.getContractId()))"),
//            @Mapping(target = "companiesA", expression = "java(com.hzhq.contract.convert.method.ContractConvertMethod.companiesVoToCompaniesDto(source.getCompaniesB()))"),
//            @Mapping(target = "companiesB", expression = "java(com.hzhq.contract.convert.method.ContractConvertMethod.companiesVoToCompaniesDto(source.getCompaniesB()))"),
//            @Mapping(target = "attachmentList", expression = "java(com.hzhq.contract.convert.method.ContractConvertMethod.attachmentsVoToAttachmentsDto(source.getAttachmentList()))"),
//            @Mapping(target = "statusList", expression = "java(com.hzhq.contract.convert.method.ContractConvertMethod.statusesVoToStatusesDto(source.getStatusList()))"),
//            @Mapping(target = "contractType", expression = "java(com.hzhq.contract.bean.entity.ContractType.builder().name(source.getContractName()).build())"),
//            @Mapping(target = "depart", expression = "java(com.hzhq.contract.bean.entity.Depart.builder().departName(source.getDepart()).build())"),
//            @Mapping(target = "createUser",expression = "java(com.hzhq.contract.bean.entity.User.builder().username(source.getCreateUser()).build())"),
//            @Mapping(target = "lastEditedUser",expression = "java(com.hzhq.contract.bean.entity.User.builder().username(source.getLastEditedUser()).build())"),
//            @Mapping(target = "approvalPerson",expression = "java(com.hzhq.contract.bean.entity.User.builder().username(source.getApprovalPerson()).build())")
//    })
//    ContractDTO voToDto(ContractVO source);


}
